import axios from "axios"
import { API_ENDPOINTS, buildUrl } from "./endpoints"

export const HOST = 'http://127.0.0.1'
export const PORT = 8000
const API_VERSION = 'v1'

const BASE_URL = `${HOST}:${PORT}/api/${API_VERSION}`

axios.interceptors.response.use(
    response => response,
    error => {
        console.error('global catch error: ', {
            url: error.config?.url,
            method: error.config?.method,
            status: error.response?.status,
            message: error.message
        })
        return Promise.reject(error);
    }
)

const service = axios.create({
    baseURL: BASE_URL,
    timeout: 5000
})

export default service;

export const api = {
    completeConversation: `/api/${API_VERSION}${buildUrl('chat', API_ENDPOINTS.chat.completion)}`
}
